Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Conversation

@xsalonx
Copy link
Collaborator

@xsalonx xsalonx commented Aug 2, 2023

I have a JIRA ticket

  • branch and/or PR name(s) include(s) JIRA ID
  • issue has "Fix version" assigned
  • issue "Status" is set to "In review"
  • PR labels are selected

Notable changes for users:

  • added possibility to filter fetched data
    Example:

Client use url:

  const URL  = .../?filter[or][field1][gt]=10&filter[or][field1][lt]=3&filter[or][field1][_goperator]=or&filter[or][filed2][like]=LHC_%pass&filter[or][filed2][notLike]=LHC_c%  

The url will be parsed by qs in express to:

  const query = {
      "filter": {
          "or": {
              "field1": {
                  "gt": "10",
                  "lt": "3",
                  "_goperator": "or"
              },
              "filed2": {
                  "like": "LHC_%pass",
                  "notLike": "LHC_c%"
              }
      }
} 

query.filter is being passed as an argument to filterToSequelizeWhereClause function
which returns sequelize-compatible where-clause

 const whereClause = {
 [Symbol(or)]: {
   field1: {
     [Symbol(or)]: {
       [Symbol(gt)]: '10',
       [Symbol(lt)]: '3'
     }
   },
   filed2: {
     [Symbol(and)]: {
       [Symbol(like)]: 'LHC_%pass',
       [Symbol(notLike)]: 'LHC_c%'
     }
   }
 }
} 

What is equivalent to sql:

  WHERE (field1 > 10 OR field1 < 3) OR (field2 like 'LHC_%pass' AND field2 NOT LIKE 'LHC_c%') 

##!!! For entity Run filtering with columns runDuration, endTime, startTime is not supported because they are virtual fields, which with sequelize quering is not possible

Notable changes for developers:

  • details of previous in docs of mentioned function filterToSequelizeWhereClause
  • func validateDTO renamed to validateDtoOrRepondOnFailure
  • object STDEntiryDTO renamed to stdDataRequestDTO
  • introduced controllerHandlerWrapper for handling all uncaught errors during processing clients requests
  • tests

@xsalonx xsalonx requested a review from Ehevi August 2, 2023 09:47
@xsalonx xsalonx self-assigned this Aug 2, 2023
@xsalonx xsalonx marked this pull request as ready for review August 3, 2023 08:48
@xsalonx xsalonx requested a review from Ehevi August 3, 2023 08:48
@xsalonx xsalonx force-pushed the improvement/ORCT-134/filtering-for-new-api branch 2 times, most recently from 479068b to f8dfd48 Compare August 3, 2023 09:07
@xsalonx xsalonx force-pushed the improvement/ORCT-134/filtering-for-new-api branch from f8dfd48 to 906cbb4 Compare August 3, 2023 09:09
@Ehevi Ehevi merged commit 4599758 into master Aug 3, 2023
@Ehevi Ehevi deleted the improvement/ORCT-134/filtering-for-new-api branch August 3, 2023 09:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants